(define append
  (native_function "
    Proc.new() do |arguments, interpreter|
      arg1 = interpreter.evaluate(arguments[0])
      if arg1.is_a? Array
        arguments.map {|x| interpreter.evaluate(x) }.flatten
      elsif arg1.is_a? Hash
        result = arg1
        args = arguments.dup
        args.shift
        args.each do |argument|
          argument = interpreter.evaluate(argument)
          if argument.is_a?(Hash) 
            result.merge!(argument)
          else
            if argument.count != 2
              raise 'When appendind to hash each argument must be a pair'
            else
              result[argument[0]] = argument[1]
            end
          end
        end
        result
      end
    end
  "))
